package com.zpy.playground.redisTest;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CaffeineConfig {
    // evictionListener
    // removalListener
    @Bean("specify")
    public Cache<Integer, NestB> userInfoCache() {
        Cache<Integer, NestB> cache = Caffeine.newBuilder()
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .maximumSize(1000)
            .build();
        return cache;
    }

    @Bean("normal")
    public Cache<String, Object> normalCache() {
        Cache<String, Object> cache = Caffeine.newBuilder()
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .maximumSize(1000)
            .build();

        return cache;
    }

    @Bean("general")
    public Cache<Object, Object> generalCache() {
        Cache<Object, Object> cache = Caffeine.newBuilder()
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .maximumSize(1000)
            .build();

        return cache;
    }
}
